<div class="eject_con">
    <div id="warning" class="alert alert-error"></div>
    <form method="post" id="add_form" target="_parent" action="{:url('Sellergoodsonline/save_redpacket')}"
          enctype="multipart/form-data">
        <input type="hidden" name="commonid" value="{$commonid}"/>
        <input type="hidden" name="goods_id" value="{$goods_id}"/>
        <input type="hidden" name="goods_price" id="goods_price" value="{$goods_info.goods_price}"/>

        <dl>
            <dt><i class="required">*</i>{$Think.lang.goods_redpacket_amount}</dt>
            <dd>
                <input type="text" class="text" name="red_amount" value="" id="red_amount"/>
                <span></span>
            </dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.goods_redpacket_use_star_time}</dt>
            <dd>
                <input id="start_time" name="use_start_time" type="text" class="text w130"/><em class="add-on"><i
                    class="iconfont">&#xe8d6;</i></em>
                <span></span>
            </dd>
        </dl>
        <dl>
            <dt><i class="required">*</i>{$Think.lang.goods_redpacket_use_end_time}</dt>
            <dd>
                <input id="end_time" name="use_end_time" type="text" class="text w130"/><em class="add-on"><i
                    class="iconfont">&#xe8d6;</i></em>
                <span></span>
            </dd>
        </dl>

        <div class="bottom">
            <input type="submit" class="submit" value="{$Think.lang.ds_submit}"/>
        </div>
    </form>
</div>
<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-zh-CN.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-file-upload/jquery.fileupload.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/jquery.ajaxContent.pack.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#start_time').datetimepicker({dateFormat: 'yy-mm-dd'});
        $('#end_time').datetimepicker({dateFormat: 'yy-mm-dd'});


        jQuery.validator.methods.greaterThanDate = function (value, element, param) {
            var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };


        jQuery.validator.methods.greaterThanStartDate = function (value, element) {
            var start_date = $("#start_time").val();
            var date1 = new Date(Date.parse(start_date.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };

        jQuery.validator.methods.lessThanGoodsPrice = function (value, element) {
            var goods_price = $("#goods_price").val();
            return Number(value) < Number(goods_price);
        };


        //页面输入内容验证
        $("#add_form").validate({
            errorPlacement: function (error, element) {
                var error_td = element.parent('dd').children('span');
                error_td.append(error);
            },
            onfocusout: false,
            rules: {
                red_amount: {
                    required: true,
                    min: 0.1,
                    lessThanGoodsPrice: true,
                },
                use_start_time: {
                    required: true,
                    date: true,

                },
                use_end_time: {
                    required: true,
                    date: true,
                    greaterThanStartDate: true,
                },

            },
            messages: {
                red_amount: {
                    required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate1}',
                    min: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate3}',
                    lessThanGoodsPrice: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate4}',
                },

                use_start_time: {
                    required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate5}',
                    date: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate6}',
                },
                use_end_time: {
                    required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate7}',
                    date: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate6}',
                    greaterThanStartDate: '<i class="iconfont">&#xe64c;</i>{$Think.lang.goods_redpacket_validate8}',
                },

            }
        });


    });

</script>
